//	 ID : pallab81
// 	PROG : 4061
// 	LANG : C++
// 	2011-10-12-10.21.36 Wednesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}

int ncity;
int nedge;
int nticket;
vector< vector< pair<int,int > > > E;
vector< int > ticket;
int vis[ 103 ] ;
int dp[ 103 ][ 103 ];

inline void Read(){

    E.assign( ncity, vector< pair<int,int> >() );
    ticket.clear();
    int u,v,z;
    fo(i,nedge){
        scanf("%d %d %d",&u,&v,&z);
        E[u].pb( mk(v,z) );
        E[v].pb( mk(u,z) );
    }

    scanf("%d",&nticket);
    fo(i,nticket){
        scanf("%d",&z);
        ticket.pb( z );
    }
}

// current current ticker, current city
inline int go(int cur_ticket, int cur_city ){

    if( cur_ticket== nticket ){
        return cur_city==(ncity-1) ? 1 : 0;
    }

    int &nice = dp[ cur_ticket ][ cur_city ];
    if( nice!=-1 ){
        return nice;
    }
    nice=0;// assume nice false

    vector< pair<int,int> > cango = E[cur_city];
    int Z = ticket[ cur_ticket ];
    for(int i=0,j=SZ(cango); i<j; ++i ){
        int v = cango[i].f;
        int z = cango[i].s;
        if( Z==z ){
            if( go(cur_ticket+1,v)==1 ){
                nice=1;
            }
        }
    }
return nice;
}

int tour=1;
inline void Proc(){
    SET(dp,-1);

     go(0,0);
     if( go(0,0)!=1 ){
        printf("Tour %d: %d\n",tour,0);
     }
     else{
        SET(vis,-1);
        int total=0;
        fo(i,nticket){
            fo(j,ncity-1){
                if( dp[i][j]==1 ){
                    if( vis[j]==-1){
                        vis[j]=1;
                        ++total;
                    }
                }
            }
        }
        printf("Tour %d: %d\n",tour,total+1);
     }
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("in","rt",stdin);
	#endif
    while( scanf("%d %d",&ncity,&nedge) == 2 ){
        if( ncity==0 && nedge==0 )break;
        Read();
        Proc();
        ++tour;
    }

return 0;
}
